#include <func.h>
typedef struct {
    pthread_cond_t cond;

    pthread_mutex_t mutex;
}arg_t;

void* func(void*p)
{
    printf("child thread, ID: %ld waiting...\n",pthread_self());
    arg_t* pdata = (arg_t*)p;
    pthread_mutex_lock(&pdata->mutex);
    pthread_cond_wait(&pdata->cond,&pdata->mutex);
    pthread_mutex_unlock(&pdata->mutex);
    printf("child thread, ID: %ld wait over.\n",pthread_self());
    pthread_exit(NULL);
}
int main(int argc,char **argv)
{
    arg_t data;
    int ret;
    ret = pthread_cond_init(&data.cond,NULL);
    THREAD_ERROR_CHECK(ret,"pthread_cond_init");
    pthread_mutex_init(&data.mutex,NULL);
    pthread_t pthid[2];
    for(int i = 0;i<2;++i)
    {
        pthread_create(pthid+i,NULL,func,&data);
    }

    sleep(1);
    ret = pthread_cond_broadcast(&data.cond);
    THREAD_ERROR_CHECK(ret,"pthread_cond_broadcast");
    printf("broadcast done\n");
    for(int i= 0;i<2;++i)
    {
        pthread_join(pthid[i],NULL);
    }
    printf("main thread:join success\n");
    return 0;
}

